package com.huafeng.enums;

import com.huafeng.function.NoticeFunctions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author 花风
 * @date 2023/4/6 12:51
 * @Description 通知类型枚举
 */
public enum NoticeEnum {
    Group_Decrease("group_decrease", NoticeFunctions::groupDecrease),
    Group_Increase("group_increase",NoticeFunctions::groupIncrease),
    Friend_Add("friend_add",NoticeFunctions::friendAdd),
    Group_Recall("group_recall",NoticeFunctions::groupRecall),
    Friend_Recall("friend_recall",NoticeFunctions::friendRecall),
    Notify("notify",NoticeFunctions::Notify);
    private final String type;
    private final Function<List<String>,Object> function;

    private static final Map<String,Function<List<String>,Object>> map = new HashMap<>();
    static {
        NoticeEnum[] noticeEnums = NoticeEnum.values();
        for (NoticeEnum noticeEnum : noticeEnums) {
            map.putIfAbsent(noticeEnum.type,noticeEnum.function);
        }
    }

    public static Function<List<String>,Object> get(String type){
        Function<List<String>, Object> function = map.get(type);
        if (function == null){
            throw new NullPointerException("function is null");
        }
        return function;
    }
    NoticeEnum(String type,Function<List<String>,Object> function){
        this.type = type;
        this.function = function;
    }
}
